home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 002 / dbug / dbug.h < prev    next >
C/C++ Source or Header  |  1995-03-17  |  5KB  |  142 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1984, Fred Fish            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  *    This software and/or documentation is released into the        *
  7.  *    public domain for personal, non-commercial use only.        *
  8.  *    Limited rights to use, modify, and redistribute are hereby    *
  9.  *    granted for non-commercial purposes, provided that all        *
  10.  *    copyright notices remain intact and all changes are clearly    *
  11.  *    documented.  The author makes no warranty of any kind with    *
  12.  *    respect to this product and explicitly disclaims any implied    *
  13.  *    warranties of merchantability or fitness for any particular    *
  14.  *    purpose.                            *
  15.  *                                    *
  16.  ************************************************************************
  17.  */
  18.  
  19.  
  20. /*
  21.  *  FILE
  22.  *
  23.  *    dbug.h    user include file for programs using the dbug package
  24.  *
  25.  *  SYNOPSIS
  26.  *
  27.  *    #include <local/dbug.h>
  28.  *
  29.  *  SCCS ID
  30.  *
  31.  *    @(#)dbug.h    1.7 12/20/85
  32.  *
  33.  *  DESCRIPTION
  34.  *
  35.  *    Programs which use the dbug package must include this file.
  36.  *    It contains the appropriate macros to call support routines
  37.  *    in the dbug runtime library.
  38.  *
  39.  *    To disable compilation of the macro expansions define the
  40.  *    preprocessor symbol "DBUG_OFF".  This will result in null
  41.  *    macros expansions so that the resulting code will be smaller
  42.  *    and faster.  (The difference may be smaller than you think
  43.  *    so this step is recommended only when absolutely necessary).
  44.  *    In general, tradeoffs between space and efficiency are
  45.  *    decided in favor of efficiency since space is seldom a
  46.  *    problem on the new machines).
  47.  *
  48.  *    All externally visible symbol names follow the pattern
  49.  *    "_db_xxx..xx_" to minimize the possibility of a dbug package
  50.  *    symbol colliding with a user defined symbol.
  51.  *    
  52.  *    Because the C preprocessor will not accept macros with a variable
  53.  *    number of arguments, there are separate DBUG_<N> macros for
  54.  *    cases N = {0,1,...NMAX}.  NMAX is currently 5.
  55.  *
  56.  *  AUTHOR
  57.  *
  58.  *    Fred Fish
  59.  *    (Currently employed by UniSoft Systems, Berkeley, Ca.)
  60.  *    (415) 644-1230  ext 242
  61.  *    ucbvax!unisoft!fnf  or  dual!unisoft!fnf
  62.  *
  63.  */
  64.  
  65.  
  66. /*
  67.  *    Internally used dbug variables which must be global.
  68.  */
  69.  
  70. #ifndef DBUG_OFF
  71.     extern int _db_on_;            /* TRUE if debug currently enabled */
  72.     extern FILE *_db_fp_;        /* Current debug output stream */
  73.     extern char *_db_process_;        /* Name of current process */
  74.     extern int _db_keyword_ ();        /* Accept/reject keyword */
  75.     extern void _db_push_ ();        /* Push state, set up new state */
  76.     extern void _db_pop_ ();        /* Pop previous debug state */
  77.     extern void _db_enter_ ();        /* New user function entered */
  78.     extern void _db_return_ ();        /* User function return */
  79.     extern void _db_printf_ ();        /* Print debug output */
  80.     extern void _db_setjmp_ ();        /* Save debugger environment */
  81.     extern void _db_longjmp_ ();    /* Restore debugger environment */
  82. # endif
  83.  
  84.  
  85. /*
  86.  *    These macros provide a user interface into functions in the
  87.  *    dbug runtime support library.  They isolate users from changes
  88.  *    in the MACROS and/or runtime support.
  89.  *
  90.  *    The symbols "__LINE__" and "__FILE__" are expanded by the
  91.  *    preprocessor to the current source file line number and file
  92.  *    name respectively.
  93.  *
  94.  *    WARNING ---  Because the DBUG_ENTER macro allocates space on
  95.  *    the user function's stack, it must precede any executable
  96.  *    statements in the user function.
  97.  *
  98.  */
  99.  
  100. # ifdef DBUG_OFF
  101. #    define DBUG_ENTER(a1)
  102. #    define DBUG_RETURN(a1) return(a1)
  103. #    define DBUG_VOID_RETURN return
  104. #    define DBUG_EXECUTE(keyword,a1)
  105. #    define DBUG_2(keyword,format)
  106. #    define DBUG_3(keyword,format,a1)
  107. #    define DBUG_4(keyword,format,a1,a2)
  108. #    define DBUG_5(keyword,format,a1,a2,a3)
  109. #    define DBUG_PUSH(a1)
  110. #    define DBUG_POP()
  111. #    define DBUG_PROCESS(a1)
  112. #    define DBUG_FILE (stderr)
  113. #    define DBUG_SETJMP setjmp
  114. #    define DBUG_LONGJMP longjmp
  115. # else
  116. #    define DBUG_ENTER(a) \
  117.     auto char *_db_func_, *_db_file_; \
  118.     int _db_level_; \
  119.     _db_enter_ (a,__FILE__,__LINE__,&_db_func_,&_db_file_,&_db_level_)
  120. #    define DBUG_LEAVE \
  121.     (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_))
  122. #    define DBUG_RETURN(a1) return (DBUG_LEAVE, (a1))
  123. /*   define DBUG_RETURN(a1) {DBUG_LEAVE; return(a1);}  Alternate form */
  124. #    define DBUG_VOID_RETURN {DBUG_LEAVE; return;}
  125. #    define DBUG_EXECUTE(keyword,a1) \
  126.     {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}}
  127. #    define DBUG_2(keyword,format) \
  128.     {if (_db_on_) {_db_printf_ (__LINE__, keyword, format);}}
  129. #    define DBUG_3(keyword,format,a1) \
  130.     {if (_db_on_) {_db_printf_ (__LINE__, keyword, format, a1);}}
  131. #    define DBUG_4(keyword,format,a1,a2) \
  132.     {if (_db_on_) {_db_printf_ (__LINE__, keyword, format, a1, a2);}}
  133. #    define DBUG_5(keyword,format,a1,a2,a3) \
  134.     {if (_db_on_) {_db_printf_ (__LINE__, keyword, format, a1, a2, a3);}}
  135. #    define DBUG_PUSH(a1) _db_push_ (a1)
  136. #    define DBUG_POP() _db_pop_ ()
  137. #    define DBUG_PROCESS(a1) (_db_process_ = a1)
  138. #    define DBUG_FILE (_db_fp_)
  139. #    define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1))
  140. #    define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2))
  141. # endif
  142.